<?php
function generate_pagination_ajax($js_function, $div_id, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
{
	$total_pages = ceil($num_items/$per_page);
	if ( $total_pages == 1 )
		return '';
	$on_page = floor($start_item / $per_page) + 1;
	$page_string = '';
	if ( $total_pages > 10 ) {
		$init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
		for($i = 1; $i < $init_page_max + 1; $i++) {
			$page_string .= ( $i == $on_page ) ? '<span class="current">' . $i . '</span>' : '<a href="javascript:void(0)" onclick="'. $js_function .'(\''. $div_id .'\','. $per_page .','. ( ( $i - 1 ) * $per_page ) . ')" class="page">' . $i . '</a>';
			if ( $i <  $init_page_max )
				$page_string .= '&nbsp;';
		}
		if ( $total_pages > 3 ) {
			if ( $on_page > 1  && $on_page < $total_pages ) {
				$page_string .= ( $on_page > 5 ) ? ' ... ' : '';
				$init_page_min = ( $on_page > 4 ) ? $on_page : 5;
				$init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
				for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++) {
					$page_string .= ($i == $on_page) ? '<span class="current">' . $i . '</span>' : '<a href="javascript:void(0)" onclick="'. $js_function .'(\''. $div_id .'\','. $per_page .','. ( ( $i - 1 ) * $per_page ) . ')" class="page">' . $i . '</a>';
					if ( $i <  $init_page_max + 1 )
						$page_string .= '&nbsp;';
				}
				$page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : '';
			}
			else
				$page_string .= ' ... ';

			for($i = $total_pages - 2; $i < $total_pages + 1; $i++) {
				$page_string .= ( $i == $on_page ) ? '<span class="current">' . $i . '</span>'  : '<a href="javascript:void(0)" onclick="'. $js_function .'(\''. $div_id .'\','. $per_page .','. ( ( $i - 1 ) * $per_page ) . ')" class="page">' . $i . '</a>';
				if( $i <  $total_pages )
					$page_string .= '&nbsp;';
			}
		}
	} else {
		for($i = 1; $i < $total_pages + 1; $i++) {
			$page_string .= ( $i == $on_page ) ? '<span class="current">' . $i . '</span>' : '<a href="javascript:void(0)" onclick="'. $js_function .'(\''. $div_id .'\','. $per_page .','. ( ( $i - 1 ) * $per_page ) . ')" class="page">' . $i . '</a>';
			if ( $i <  $total_pages )
				$page_string .= '&nbsp;';
		}
	}
	if ( $add_prevnext_text ) {
		if ( $on_page > 1 )
			$page_string = '<a href="javascript:void(0)" onclick="'. $js_function .'(\''. $div_id .'\','. $per_page .','. ( ( $on_page - 2 ) * $per_page ) . ')" class="page">&lt;</a>&nbsp;' . $page_string;
		if ( $on_page < $total_pages )
			$page_string .= '&nbsp;<a href="javascript:void(0)" onclick="'. $js_function .'(\''. $div_id .'\','. $per_page .','. ( $on_page * $per_page ) . ')" class="page">&gt;</a>';
	}
	$page_string = '<div class="tnk_pagenavi">'. $page_string .'</div>';
	return $page_string;
}
$start = 0;
$limit = 20;
$mysql = $wpdb->get_col("SELECT count(*) AS total 
	FROM {$table_prefix}ibi_thanhtoan t 
	INNER JOIN $wpdb->users u ON t.user_id=u.ID;");
$total = $mysql[0];
$stt   = 0;
$mysql = $wpdb->get_results("SELECT * 
	FROM {$table_prefix}ibi_thanhtoan t 
	INNER JOIN $wpdb->users u ON t.user_id=u.ID ORDER BY ID DESC LIMIT $start, $limit");
		
generate_pagination_ajax('paginationOrder', 'forPagi', $total, $limit, $start). '&nbsp;';
?>

<script type="text/javascript">
function sprintf(format, etc) {
    var arg = arguments;
    var i = 1;
    return format.replace(/%((%)|s)/g, function (m) { return m[2] || arg[i++] })
}
var loading = '<img src="<?php echo TEMPLATE_IMG; ?>/loading/loading%s.gif" alt="" />';
function paginationOrder( idDiv, mLimit, mStart ) {
	$.ajaxSetup({cache:false});
	$('#'+ idDiv).html(sprintf(loading, 15));
	var postData	= {
		url: 	'pagination_Order', 
		start: 	mStart, 
		limit: 	mLimit,
	};
	$.ajax({
		type: "POST",
		url: "<?php echo TEMPLATE_URL; ?>/libs/actions.php",
		data: postData,
		cache: false,
		success: function(data){
			$('#'+ idDiv).html(data);
		}
	});
	return false;
}
</script>